using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for NewsAccess
/// </summary>
/// 
public struct NewsDetails
{
    public int NewsId;
    public string Name;
    public string Description;
}

public class NewsAccess
{
	public NewsAccess()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    // Get news details
    public static NewsDetails GetNewsDetails()
    {
        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "GetNewsDetails";
        // execute the stored procedure
        DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
        // wrap retrieved data into a CategoryDetails object
        NewsDetails details = new NewsDetails();
        if (table.Rows.Count > 0)
        {
            details.NewsId = Int32.Parse(table.Rows[0]["NewsID"].ToString());
            details.Name = table.Rows[0]["Name"].ToString();
            details.Description = table.Rows[0]["Description"].ToString();
        }
        // return news details
        return details;
    }

    // Update news details
    public static bool UpdateNews(string des)
    {
        // get a configured DbCommand object
        DbCommand comm = GenericDataAccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "UpdateNews";
        // create a new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@Description";
        param.Value = des;
        param.DbType = DbType.String;
        param.Size = 4000;
        comm.Parameters.Add(param);

        // result will represent the number of changed rows
        int result = -1;
        try
        {
            // execute the stored procedure
            result = GenericDataAccess.ExecuteNonQuery(comm);
        }
        catch
        {
            // any errors are logged in GenericDataAccess, we ignore them here
        }
        // result will be 1 in case of success
        return (result != -1);
    }
}
